import pickle
import tkinter
from tkinter import *
from tkinter import ttk
import tkinter.messagebox
import numpy as np
from PIL import Image, ImageTk


# 构造输入算法的特征的函数
def build_feature(age, gender, province, city, money, years, numbers):
    feature_list = []

    # 性别转换
    if gender == "男":
        feature_list.append(0)
        feature_list.append(1)
    elif gender == "女":
        feature_list.append(1)
        feature_list.append(0)

    # 年龄转换
    if age == "16-20岁":
        for i in range(0):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(8):
            feature_list.append(0)
    elif age == "21-25岁":
        for i in range(1):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(7):
            feature_list.append(0)
    elif age == "26-30岁":
        for i in range(2):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(6):
            feature_list.append(0)
    elif age == "31-35岁":
        for i in range(3):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(5):
            feature_list.append(0)
    elif age == "36-40岁":
        for i in range(4):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(4):
            feature_list.append(0)
    elif age == "41-45岁":
        for i in range(5):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(3):
            feature_list.append(0)
    elif age == "46-50岁":
        for i in range(6):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(2):
            feature_list.append(0)
    elif age == "51-55岁":
        for i in range(7):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(1):
            feature_list.append(0)
    elif age == "56-60岁":
        for i in range(8):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(0):
            feature_list.append(0)

    # 基本保额段转换
    if money == "00-05万不含":
        for i in range(0):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(12):
            feature_list.append(0)
    elif money == "05-10万不含":
        for i in range(1):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(11):
            feature_list.append(0)
    elif money == "10-15万不含":
        for i in range(2):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(10):
            feature_list.append(0)
    elif money == "100万以上":
        for i in range(3):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(9):
            feature_list.append(0)
    elif money == "15-20万不含":
        for i in range(4):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(8):
            feature_list.append(0)
    elif money == "20-30万不含":
        for i in range(5):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(7):
            feature_list.append(0)
    elif money == "30-40万不含":
        for i in range(6):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(6):
            feature_list.append(0)
    elif money == "40-50万不含":
        for i in range(7):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(5):
            feature_list.append(0)
    elif money == "50-60万不含":
        for i in range(8):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(4):
            feature_list.append(0)
    elif money == "60-70万不含":
        for i in range(9):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(3):
            feature_list.append(0)
    elif money == "70-80万不含":
        for i in range(10):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(2):
            feature_list.append(0)
    elif money == "80-90万不含":
        for i in range(11):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(1):
            feature_list.append(0)
    elif money == "90-100万不含":
        for i in range(12):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(0):
            feature_list.append(0)

    # 城市线转换
    if (city in ["北京市", "上海市", "广州市", "深圳市"]):
        for i in range(0):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(5):
            feature_list.append(0)
    elif (city in ['三亚市', '上饶市', '临沂市', '九江市', '信阳市', '包头市', '南阳市', '吉林市', '呼和浩特市', '咸阳市', '唐山市',
                  '商丘市', '大庆市', '威海市', '宁德市', '宜昌市', '宜春市', '宿迁市', '岳阳市', '巢湖市', '常德市', '廊坊市',
                  '德阳市', '扬州市', '揭阳市', '新乡市', '曲靖市', '柳州市', '株洲市', '桂林市', '汕头市', '江门市', '沧州市',
                  '泰州市', '洛阳市', '济宁市', '海口市', '淄博市', '淮安市', '湖北省辖市区', '湖州市', '湘潭市', '湛江市', '滁州市',
                  '漳州市', '潮州市', '珠海市', '盐城市', '省直辖行政单位', '秦皇岛市', '绵阳市', '肇庆市', '芜湖市', '荆州市',
                  '莆田市', '菏泽市', '蚌埠市', '衡阳市', '襄樊市', '西宁市', '许昌市', '赣州市', '连云港市', '遵义市', '邢台市',
                  '邯郸市', '铜陵市', '银川市', '镇江市', '阜阳市', '鞍山市', '驻马店市', '黄冈市']):
        for i in range(1):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(4):
            feature_list.append(0)
    elif (city in ['中山市', '乌鲁木齐市', '佛山市', '保定市', '兰州市', '南宁市', '南昌市', '南通市', '厦门市', '台州市', '合肥市',
                  '哈尔滨市', '嘉兴市', '大连市', '太原市', '常州市', '徐州市', '惠州市', '昆明市', '泉州市', '济南市', '温州市',
                  '潍坊市', '烟台市', '石家庄市', '福州市', '绍兴市', '贵阳市', '金华市', '长春市']):
        for i in range(2):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(3):
            feature_list.append(0)
    elif (city in ['七台河市', '三门峡市', '中卫市', '临夏回族自治州', '乌兰察布市', '乌海市', '云浮市', '伊春市', '伊犁哈萨克自治州',
                  '保山市', '克拉玛依市', '六盘水市', '兴安盟', '凉山彝族自治州', '博尔塔拉蒙古自治州', '双鸭山市', '吐鲁番市',
                  '吕梁市', '吴忠市', '哈密市', '商洛市', '嘉峪关市', '四平市', '固原市', '塔城地区', '天水市', '安康市', '定西市',
                  '崇左市', '巴中市', '巴彦淖尔市', '巴音郭楞蒙古自治州', '平凉市', '广元市', '广安市', '庆阳市', '延安市', '张家界市',
                  '张掖市', '忻州市', '恩施土家族苗族自治州', '攀枝花市', '文山壮族苗族自治州', '新余市', '昌吉回族自治州', '晋城市',
                  '普洱市', '景德镇市', '朔州市', '朝阳市', '本溪市', '梧州市', '楚雄彝族自治州', '武威市', '汉中市', '池州市',
                  '河池市', '海东市', '海北藏族自治州', '海南藏族自治州', '海西蒙古族藏族自治州', '淮北市', '湘西土家族苗族自治州',
                  '白城市', '白山市', '白银市', '百色市', '石嘴山市', '绥化市', '自贡市', '荆门市', '莱芜市', '萍乡市', '葫芦岛市',
                  '西双版纳傣族自治州', '贵港市', '贺州市', '资阳市', '辽源市', '辽阳市', '达州市', '鄂州市', '酒泉市', '金昌市',
                  '钦州市', '铁岭市', '铜川市', '锡林郭勒盟', '长治市', '阜新市', '防城港市', '阳泉市', '阿克苏地区', '阿勒泰地区',
                  '阿坝藏族羌族自治州', '陇南市', '随州市', '雅安市', '鸡西市', '鹤壁市', '鹤岗市', '鹰潭市', '黑河市']):
        for i in range(3):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(2):
            feature_list.append(0)
    elif (city in ['三明市', '东营市', '临汾市', '丹东市', '丽水市', '乐山市', '亳州市', '佳木斯市', '六安市', '内江市', '北海市',
                  '十堰市', '南充市', '南平市', '吉安市', '周口市', '呼伦贝尔市', '咸宁市', '大同市', '大理白族自治州', '娄底市',
                  '孝感市', '安庆市', '安阳市', '安顺市', '宜宾市', '宝鸡市', '宣城市', '宿州市', '巢湖市', '平顶山市',
                  '延边朝鲜族自治州', '开封市', '张家口市', '德州市', '怀化市', '承德市', '抚州市', '抚顺市', '日照市', '晋中市',
                  '松原市', '枣庄市', '梅州市', '榆林市', '毕节市', '永州市', '汕尾市', '河源市', '泰安市', '泸州市', '淮南市',
                  '清远市', '渭南市', '滨州市', '漯河市', '濮阳市', '焦作市', '牡丹江市', '玉林市', '玉溪市', '益阳市', '盘锦市',
                  '省直辖县级行政区划', '眉山市', '红河哈尼族彝族自治州', '聊城市', '舟山市', '茂名市', '营口市', '衡水市', '衢州市',
                  '赤峰市', '运城市', '通化市', '通辽市', '遂宁市', '邵阳市', '郴州市', '鄂尔多斯市', '铜仁市', '锦州市', '阳江市',
                  '韶关市', '马鞍山市', '黄山市', '黄石市', '黔东南苗族侗族自治州', '黔南布依族苗族自治州', '齐齐哈尔市', '龙岩市']):
        for i in range(4):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(1):
            feature_list.append(0)
    elif (city in ['东莞市', '南京市', '天津市', '宁波市', '成都市', '无锡市', '杭州市', '武汉市', '沈阳市', '苏州市', '西安市',
                  '郑州市', '重庆市', '长沙市', '青岛市']):
        for i in range(5):
            feature_list.append(0)
        feature_list.append(1)
        for i in range(0):
            feature_list.append(0)

    # 缴费年限转换
    if years == "10":
        feature_list.append(0)
    elif years == "15":
        feature_list.append(0.25)
    elif years == "19":
        feature_list.append(0.45)
    elif years == "20":
        feature_list.append(0.5)
    elif years == "29":
        feature_list.append(0.95)
    elif years == "30":
        feature_list.append(1)

    # 保单件数转换
    numbers_encode = (eval(numbers) - 1)/197
    feature_list.append(numbers_encode)

    # 其他值补充
    if province == "安徽省":
        extend = [0.458854842, 0.193707401, 0.524453007, 0.417374049, 0.545165512,
                  0.307888207, 0.132776883, 0.100990214, 0.024273364, 0.128861448,
                  0.273594385, 0.454977731, 0.840725806, 0.143929819, 0.377727818,
                  0.717391304, 0.646153846]
        feature_list += extend
    elif province == "北京市":
        extend = [0.13297802, 1.0, 0.608738261, 0.43895922, 0.688582024,
                  1.0, 0.133118337, 0.003850868, 0.0, 0.082749955,
                  0.073129313, 0.392015305, 0.818548387, 0.033083042, 0.821723675,
                  0.869565217, 0.8]
        feature_list += extend
    elif province == "福建省":
        extend = [0.296582215, 0.445351129, 0.399562165, 0.636283737, 0.343978533,
                  0.304681857, 0.435219741, 0.258282986, 0.229747398, 0.039054351,
                  0.298761587, 0.346903212, 0.804435484, 0.002230317, 0.213917465,
                  0.202898551, 0.374358974]
        feature_list += extend
    elif province == "甘肃省":
        extend = [0.15901494, 0.012033777, 0.261398853, 0.162309803, 0.272279878,
                  0.454171761, 0.49981812, 0.065882035, 0.012592132, 0.017939065,
                  0.297426106, 0.57733167, 0.568548387, 0.170693629, 0.791885402,
                  0.336956522, 0.712820513]
        feature_list += extend
    elif province == "广东省":
        extend = [1, 0.157322149, 0.585844195, 0.904190227, 0.259881381,
                  0.181282601, 0.373340128, 0.135061885, 0.008350811, 1.0,
                  0.60222509, 0.351234307, 0.733870968, 0.0, 0.283528332,
                  0.289855072, 0.538461538]
        feature_list += extend
    elif province == "广西壮族自治区":
        extend = [0.368085433, 0.009269225, 0.385379974, 0.653230981, 0.132709244,
                  0.04646784, 0.238796776, 0.342851395, 0.039779147, 0.057309837,
                  0.379229645, 0.773413458, 0.693548387, 0.07880455, 0.27876127,
                  0.398550725, 0.215384615]
        feature_list += extend
    elif province == "贵州省":
        extend = [0.271784364, 0.069307416, 0.304302242, 0.616358124, 0.0,
                  0.025273193, 0.044808605, 0.226835213, 0.005486849, 0.066657393,
                  0.30717341, 0.923144739, 0.262096774, 0.009887741, 0.000129476,
                  0.235507246, 0.020512821]
        feature_list += extend
    elif province == "海南省":
        extend = [0.034618412, 0.05488776, 0.456506797, 0.55584317, 0.057071257,
                  0.0, 0.112012505, 0.286444596, 0.23426494, 0.018857353,
                  0.012810803, 0.180149202, 0.747983871, 0.043119471, 0.5929165,
                  0.0, 0.066666667]
        feature_list += extend
    elif province == "河北省":
        extend = [0.571963574, 0.005084842, 0.476137081, 0.239993312, 0.736551702,
                  0.474198145, 0.17420955, 0.008713855, 0.000261722, 0.119737605,
                  1.0, 0.416789436, 0.903225806, 0.12608728, 0.573918878,
                  0.945652174, 0.876923077]
        feature_list += extend
    elif province == "河南省":
        extend = [0.778105487, 0.072278366, 0.361908977, 0.095485405, 0.71073243,
                  0.349221247, 0.215427736, 0.018304363, 0.001244892, 0.197184353,
                  0.862407066, 0.715544935, 0.877016129, 0.013604936, 0.481355493,
                  1.0, 0.938461538]
        feature_list += extend
    elif province == "黑龙江省":
        extend = [0.215891776, 0.0, 0.480321255, 0.318601565, 0.527864875,
                  0.263739514, 0.483023365, 0.194861729, 0.09489592, 0.02149171,
                  0.205572326, 0.373285706, 0.502016129, 0.11374619, 0.672697097,
                  0.344202899, 0.0]
        feature_list += extend
    elif province == "湖北省":
        extend = [0.431586514, 0.183975685, 0.751425072, 0.495117476, 0.282206007,
                  0.133685009, 0.0, 0.131204958, 0.046636929, 0.352063668,
                  0.405559526, 0.91214757, 0.79233871, 0.089287042, 0.332081735,
                  0.721014493, 0.58974359]
        feature_list += extend
    elif province == "湖南省":
        extend = [0.503968992, 0.084262623, 0.549693896, 0.645003013, 0.29040134,
                  0.083923233, 0.283751229, 0.208166705, 0.032426316, 0.077646242,
                  0.694625009, 0.984830807, 0.786290323, 0.073823508, 0.233385908,
                  0.59057971, 0.379487179]
        feature_list += extend
    elif province == "吉林省":
        extend = [0.151134272, 0.022787323, 0.536822886, 0.288732602, 0.482517811,
                  0.260974852, 0.233504232, 0.118548887, 0.010775213, 0.002173612,
                  0.227287758, 0.314824098, 0.389112903, 0.106014423, 0.957390711,
                  0.481884058, 0.415384615]
        feature_list += extend
    elif province == "江苏省":
        extend = [0.656382786, 0.336905695, 0.589349301, 0.475072555, 0.483748409,
                  0.505456437, 0.146610936, 0.038125739, 0.008414992, 0.177412436,
                  0.370440218, 0.590955983, 0.782258065, 0.076648576, 0.478083288,
                  0.634057971, 0.964102564]
        feature_list += extend
    elif province == "江西省":
        extend = [0.326964369, 0.091823877, 0.604262596, 0.523950511, 0.245215811,
                  0.294144214, 0.128387734, 0.299345502, 0.119041059, 0.110204456,
                  0.423846654, 0.642276786, 0.737903226, 0.037543677, 0.389557193,
                  0.496376812, 0.358974359]
        feature_list += extend
    elif province == "辽宁省":
        extend = [0.305336763, 0.031871222, 0.740095016, 0.476825659, 0.656418205,
                  0.504673129, 0.21870587, 0.035186632, 0.002641277, 0.021066758,
                  0.395306617, 0.481799201, 0.602822581, 0.140881719, 0.795287083,
                  0.579710145, 0.58974359]
        feature_list += extend
    elif province == "内蒙古自治区":
        extend = [0.150931938, 0.006447667, 0.478378247, 0.754305021, 0.437422593,
                  0.852871122, 0.285939798, 0.127379723, 0.014627028, 0.015676235,
                  0.255138721, 0.296543545, 0.342741935, 0.099843878, 0.941218014,
                  0.31884058, 0.630769231]
        feature_list += extend
    elif province == "宁夏回族自治区":
        extend = [0.010647951, 0.022688367, 0.383280593, 0.083821189, 0.139566328,
                  0.444216374, 0.285848858, 0.005966298, 6.70159e-05, 0.001771275,
                  0.0, 0.538919947, 0.695564516, 0.087577132, 1.0,
                  0.442028986, 0.707692308]
        feature_list += extend
    elif province == "青海省":
        extend = [0.0, 0.011802385, 0.0, 0.426150205, 0.023590836,
                  0.610075054, 0.316706732, 1.0, 1.0, 0.00710234,
                  0.025538406, 0.529915099, 0.197580645, 0.192625084, 0.82612585,
                  0.246376812, 0.779487179]
        feature_list += extend
    elif province == "山东省":
        extend = [0.796108319, 0.017646407, 0.450352133, 0.26664912, 0.915154178,
                  0.591370288, 0.02949892, 0.010927312, 0.000523942, 0.143661415,
                  0.975007733, 0.626356459, 0.764112903, 0.107426957, 0.713223004,
                  0.742753623, 1.0]
        feature_list += extend
    elif province == "山西省":
        extend = [0.241419005, 0.054544306, 0.336181522, 0.0, 0.552719825,
                  0.514545446, 0.101513209, 0.017266145, 0.000283431, 0.028290453,
                  0.479670183, 0.184644621, 0.610887097, 0.050628206, 0.890039784,
                  0.778985507, 0.820512821]
        feature_list += extend
    elif province == "陕西省":
        extend = [0.279835514, 0.103246917, 0.337199826, 0.019386805, 0.290927724,
                  0.433990799, 0.076703712, 0.070851904, 0.0069265, 0.029019851,
                  0.403080566, 0.748850789, 0.943548387, 0.090030481, 0.499264342,
                  0.710144928, 0.584615385]
        feature_list += extend
    elif province == "上海市":
        extend = [0.157774721, 0.787883188, 0.57548034, 0.594453474, 0.532541239,
                  0.773750026, 0.315103269, 0.008751451, 0.000341374, 0.077420916,
                  0.012221997, 0.503468539, 0.830645161, 0.126458999, 0.347665906,
                  0.510869565, 0.958974359]
        feature_list += extend
    elif province == "四川省":
        extend = [0.647446464, 0.115603255, 0.881135304, 0.996288932, 0.336938151,
                  0.314778578, 0.534431993, 0.231833978, 0.015576345, 0.157022873,
                  0.985514512, 0.970345033, 0.631048387, 0.057690878, 0.0,
                  0.5, 0.333333333]
        feature_list += extend
    elif province == "天津市":
        extend = [0.066134963, 0.225602563, 0.77420215, 0.447430233, 1.0,
                  0.587600517, 0.252546753, 0.0, 3.66714e-05, 0.0,
                  0.015908436, 0.0, 0.822580645, 0.110103338, 0.760316862,
                  0.913043478, 0.753846154]
        feature_list += extend
    elif province == "新疆维吾尔自治区":
        extend = [0.16594744, 0.057249802, 0.524158766, 0.347395821, 0.184086631,
                  0.716927833, 0.253887691, 0.299820258, 0.031541041, 0.074058789,
                  0.181542203, 0.983639529, 0.590725806, 1.0, 0.930141952,
                  0.688405797, 0.384615385]
        feature_list += extend
    elif province == "云南省":
        extend = [0.343790636, 0.14277015, 0.415108981, 0.646583033, 0.045789655,
                  0.047517355, 0.242450682, 0.314568921, 0.04929294, 0.110648242,
                  0.264604422, 0.753475653, 0.0, 0.053750651, 0.684620636,
                  0.155797101, 0.241025641]
        feature_list += extend
    elif province == "浙江省":
        extend = [0.488336561, 0.200454544, 0.466573418, 0.525755937, 0.323789356,
                  0.389970424, 0.368485984, 0.153267133, 0.030419875, 0.178517305,
                  0.362032662, 0.536100605, 0.915322581, 0.089212698, 0.302902611,
                  0.413043478, 0.548717949]
        feature_list += extend
    elif province == "重庆市":
        extend = [0.217591114, 0.161858822, 1.0, 1.0, 0.431467916,
                  0.47069236, 1.0, 0.13205318, 0.009604481, 0.018025004,
                  0.204140844, 1.0, 1.0, 0.467994945, 0.010040255,
                  0.59057971, 0.0]
        feature_list += extend

    return feature_list


# 预测函数
def predict():
    age = comvalue_age.get()
    gender = comvalue_gender.get()
    province = comvalue_province.get()
    city = comvalue_city.get()
    money = comvalue_money.get()
    years = comvalue_years.get()
    numbers = entry_numbers.get()

    if age == "" or gender == "" or province == "" \
            or city == "" or money == "" or years == "" or numbers == "":
        # 判断是否输入了所有信息
        tkinter.messagebox.showinfo("提示", "请完善被保险人信息再进行预测！")
    elif not numbers.isdecimal():
        # 判断输入的保单件数是否是整数
        tkinter.messagebox.showinfo("提示", "保单件数请输入整数！")
    else:
        with open('./resource/ANN.pickle', 'rb') as fr:
            ANN = pickle.load(fr)
        feature_list = build_feature(age, gender, province, city, money, years, numbers)
        score = ANN.predict_proba(np.array([feature_list]))
        risk = "被保险人出险概率：" + str(round(score[0][1], 5)*100) + "%"
        tkinter.messagebox.showinfo("客户风险程度", risk)


# 选定省份再选城市
def city(event):
    if comvalue_province.get() == "安徽省":
        combobox_city["values"] = ("合肥市", "阜阳市", "宿州市", "毫州市", "淮北市", "安庆市", "六安市", "芜湖市", "淮南市",
                                   "蚌埠市", "宣城市", "铜陵市", "滁州市", "马鞍山市", "黄山市", "巢湖市", "池州市")
    elif comvalue_province.get() == "北京市":
        combobox_city["values"] = "北京市"
    elif comvalue_province.get() == "福建省":
        combobox_city["values"] = ("福州市", "泉州市", "厦门市", "漳州市", "宁德市", "三明市", "南平市", "龙岩市", "莆田市")
    elif comvalue_province.get() == "甘肃省":
        combobox_city["values"] = ("兰州市", "酒泉市", "庆阳市", "张掖市", "白银市", "天水市", "平凉市", "嘉峪关市", "武威市",
                                   "定西市", "金昌市", "临夏回族自治州", "陇南市")
    elif comvalue_province.get() == "广东省":
        combobox_city["values"] = ("深圳市", "广州市", "东菀市", "佛山市", "惠州市", "珠海市", "中山市", "揭阳市", "江门市",
                                   "湛江市", "汕头市", "茂名市", "清远市", "肇庆市", "汕尾市", "阳江市", "韶关市", "河源市",
                                   "潮州市", "梅州市", "云浮市")
    elif comvalue_province.get() == "广西壮族自治区":
        combobox_city["values"] = ("南宁市", "玉林市", "柳州市", "桂林市", "贵港市", "钦州市", "北海市", "贺州市", "防城港市",
                                   "梧州市", "百色市", "崇左市", "河池市")
    elif comvalue_province.get() == "贵州省":
        combobox_city["values"] = ("贵阳市", "遵义市", "毕节市", "六盘水市", "黔南布依族苗族自治州", "安顺市", "黔东南苗族侗族自治州",
                                   "铜仁市")
    elif comvalue_province.get() == "海南省":
        combobox_city["values"] = ("海口市", "三亚市", "省直辖行政单位")
    elif comvalue_province.get() == "河北省":
        combobox_city["values"] = ("石家庄市", "保定市", "廊坊市", "沧州市", "邯郸市", "唐山市", "邢台市", "秦皇岛市", "张家口市",
                                   "衡水市", "承德市")
    elif comvalue_province.get() == "河南省":
        combobox_city["values"] = ("郑州市", "新乡市", "开封市", "洛阳市", "濮阳市", "焦作市", "南阳市", "周口市", "安阳市",
                                   "许昌市", "驻马店市", "省直辖县级行政区划", "平顶山市", "信阳市", "商丘市", "漯河市", "鹤壁市",
                                   "三门峡市")
    elif comvalue_province.get() == "黑龙江省":
        combobox_city["values"] = ("哈尔滨市", "齐齐哈尔市", "双鸭山市", "大庆市", "佳木斯市", "牡丹江市", "鸡西市", "绥化市",
                                   "伊春市", "黑河市", "鹤岗市", "七台河市")
    elif comvalue_province.get() == "湖北省":
        combobox_city["values"] = ("武汉市", "襄樊市", "荆州市", "宜昌市", "十堰市", "湖北省辖市区", "荆门市", "黄冈市", "孝感市",
                                   "黄石市", "咸宁市", "随州市", "鄂州市", "恩施土家族苗族自治州")
    elif comvalue_province.get() == "湖南省":
        combobox_city["values"] = ("长沙市", "衡阳市", "湘潭市", "邵阳市", "娄底市", "岳阳市", "怀化市", "常德市", "株洲市",
                                   "永州市", "郴州市", "张家界市", "益阳市", "湘西土家族苗族自治州")
    elif comvalue_province.get() == "吉林省":
        combobox_city["values"] = ("长春市", "吉林市", "通化市", "四平市", "松原市", "延边朝鲜族自治州", "白山市", "白城市",
                                   "辽源市")
    elif comvalue_province.get() == "江苏省":
        combobox_city["values"] = ("苏州市", "南京市", "无锡市", "南通市", "盐城市", "常州市", "徐州市", "镇江市", "扬州市",
                                   "泰州市", "连云港市", "宿迁市", "淮安市")
    elif comvalue_province.get() == "江西省":
        combobox_city["values"] = ("南昌市", "赣州市", "宜春市", "九江市", "上饶市", "鹰潭市", "吉安市", "抚州市", "景德镇市",
                                   "新余市", "萍乡市")
    elif comvalue_province.get() == "辽宁省":
        combobox_city["values"] = ("大连市", "沈阳市", "鞍山市", "盘锦市", "营口市", "葫芦岛市", "锦州市", "朝阳市", "铁岭市",
                                   "抚顺市", "本溪市", "辽阳市", "丹东市", "阜新市")
    elif comvalue_province.get() == "内蒙古自治区":
        combobox_city["values"] = ("赤峰市", "呼和浩特市", "包头市", "呼伦贝尔市", "通辽市", "巴彦淖尔市", "鄂尔多斯市", "兴安盟",
                                   "乌兰察布市", "乌海市", "锡林郭勒盟")
    elif comvalue_province.get() == "宁夏回族自治区":
        combobox_city["values"] = ("银川市", "中卫市", "吴忠市", "石嘴山市", "固原市")
    elif comvalue_province.get() == "青海省":
        combobox_city["values"] = ("西宁市", "海东市", "北海藏族自治州", "海西蒙古族自治州", "海南藏族自治州")
    elif comvalue_province.get() == "山东省":
        combobox_city["values"] = ("青岛市", "济南市", "临沂市", "淄博市", "烟台市", "潍坊市", "济宁市", "威海市", "日照市",
                                   "滨州市", "东营市", "泰安市", "菏泽市", "聊城市", "德州市", "枣庄市", "莱芜市")
    elif comvalue_province.get() == "山西省":
        combobox_city["values"] = ("太原市", "运城市", "长治市", "大同市", "临汾市", "晋城市", "晋中市", "阳泉市", "吕梁市",
                                   "忻州市", "朔州市")
    elif comvalue_province.get() == "陕西省":
        combobox_city["values"] = ("西安市", "咸阳市", "榆林市", "延安市", "渭南市", "宝鸡市", "汉中市", "安康市", "商洛市",
                                   "铜川市")
    elif comvalue_province.get() == "上海市":
        combobox_city["values"] = "上海市"
    elif comvalue_province.get() == "四川省":
        combobox_city["values"] = ("成都市", "泸州市", "攀枝花市", "绵阳市", "自贡市", "宜宾市", "内江市", "德州市", "乐山市",
                                   "眉山市", "南充市", "广安市", "遂宁市", "达州市", "巴中市", "广元市", "资阳市", "雅安市",
                                   "凉山彝族自治州", "阿坝藏族羌族自治州")
    elif comvalue_province.get() == "天津市":
        combobox_city["values"] = "天津市"
    elif comvalue_province.get() == "新疆维吾尔自治区":
        combobox_city["values"] = ("乌鲁木齐市", "昌吉回族自治州", "巴音郭楞蒙古自治州", "伊犁哈萨克自治州", "省直辖行政单位",
                                   "塔城地区", "阿勒泰地区", "哈密市", "阿克苏地区", "博尔塔拉蒙古自治州", "吐鲁番市", "克拉玛依市")
    elif comvalue_province.get() == "云南省":
        combobox_city["values"] = ("昆明市", "曲靖市", "红河哈尼族彝族自治州", "玉溪市", "文山壮族苗族自治州", "保山市", "普洱市",
                                   "大理白族自治州", "楚雄彝族自治州", "西双版纳傣族自治州")
    elif comvalue_province.get() == "浙江省":
        combobox_city["values"] = ("杭州市", "宁波市", "金华市", "绍兴市", "嘉兴市", "温州市", "台州市", "湖州市", "丽水市",
                                   "衢州市", "舟山市")
    elif comvalue_province.get() == "重庆市":
        combobox_city["values"] = "重庆市"

    # 选择另一个省份后，选择的城市清空
    combobox_city.set("")


# 创建窗口、设置大小
top = Tk()
top.geometry("800x450")
top.title("风险预测")
top.resizable(False, False)

# 设置背景图片
canvas = Canvas(top, width=800, height=450)
canvas.pack()
img = ImageTk.PhotoImage(Image.open("./resource/background.gif").resize((800, 450), Image.ANTIALIAS))
canvas.background = img
bg = canvas.create_image(0, 0, anchor=NW, image=img)

# 文字提示
label_1 = Label(top, text="投保年龄段：", font=("Times", 10))
label_1.place(x=60, y=210)

# 年龄段下拉列表
comvalue_age = tkinter.StringVar()
combobox_age = ttk.Combobox(top, textvariable=comvalue_age, state="readonly")
combobox_age["values"] = ("16-20岁", "21-25岁", "26-30岁", "31-35岁", "36-40岁", "41-45岁", "46-50岁", "51-55岁", "56-60岁")
combobox_age.place(x=177, y=210)

# 文字提示
label_2 = Label(top, text="性别：", font=("Times", 10))
label_2.place(x=460, y=210)

# 性别下拉列表
comvalue_gender = tkinter.StringVar()
combobox_gender = ttk.Combobox(top, textvariable=comvalue_gender, state="readonly")
combobox_gender["values"] = ("男", "女")
combobox_gender.place(x=577, y=210)

# 文字提示
label_3 = Label(top, text="居住省份：", font=("Times", 10))
label_3.place(x=60, y=260)

# 居住省份下拉列表
comvalue_province = tkinter.StringVar()
combobox_province = ttk.Combobox(top, textvariable=comvalue_province, state="readonly")
combobox_province["values"] = ("安徽省", "北京市", "福建省", "甘肃省", "广东省", "广西壮族自治区", "贵州省", "海南省", "河北省",
                               "河南省", "黑龙江省", "湖北省", "湖南省", "吉林省", "江苏省", "江西省", "辽宁省", "内蒙古自治区",
                               "宁夏回族自治区", "青海省", "山东省", "山西省", "陕西省", "上海市", "四川省", "天津市",
                               "新疆维吾尔自治区", "云南省", "浙江省", "重庆市")
combobox_province.bind("<<ComboboxSelected>>", city)
combobox_province.place(x=177, y=260)

# 文字提示
label_4 = Label(top, text="居住城市：", font=("Times", 10))
label_4.place(x=460, y=260)

# 居住城市下拉列表
comvalue_city = tkinter.StringVar()
combobox_city = ttk.Combobox(top, textvariable=comvalue_city, state="readonly")
combobox_city["values"] = "请先选择省份"
combobox_city.place(x=577, y=260)

# 文字提示
label_5 = Label(top, text="基本保额段：", font=("Times", 10))
label_5.place(x=60, y=310)

# 基本保额段下拉列表
comvalue_money = tkinter.StringVar()
combobox_money = ttk.Combobox(top, textvariable=comvalue_money, state="readonly")
combobox_money["values"] = ("00-05万不含", "05-10万不含", "10-15万不含", "15-20万不含", "20-30万不含", "30-40万不含",
                            "40-50万不含", "50-60万不含", "60-70万不含", "70-80万不含", "80-90万不含", "90-100万不含",
                            "100万以上")
combobox_money.place(x=177, y=310)

# 文字提示
label_6 = Label(top, text="缴费年限：", font=("Times", 10))
label_6.place(x=460, y=310)

# 基本保额段下拉列表
comvalue_years = tkinter.StringVar()
combobox_years = ttk.Combobox(top, textvariable=comvalue_years, state="readonly")
combobox_years["values"] = ("10", "15", "19", "20", "29", "30")
combobox_years.place(x=577, y=310)

# 文字提示
label_7 = Label(top, text="保单件数：", font=("Times", 10))
label_7.place(x=60, y=360)

entry_numbers = Entry(top)
entry_numbers.place(x=177, y=360)

# 提交按钮
button_1 = Button(top, text="预测", font=("黑体", 16), command=predict, fg="blue")
button_1.place(x=460, y=360)

# 输出窗口
top.mainloop()
